"""
test
    >>> avg = mavg()
    >>> avg(50)
    50.0
    >>> avg(50)
    50.0
    >>> avg(20)
    40.0
    >>> avg.__code__.co_freevars
    ('s',)
"""


def mavg():
    s = []

    def avg(newval):
        s.append(newval)
        return sum(s) / len(s)

    return avg


def test():
    avg = mavg()
    avg(50)
    avg(50)
    avg(100)
    avg.__code__.co_freevars


if __name__ == "__main__":
    import doctest

    print("开始测试")
    doctest.testmod()
    print("完成测试")
